﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace LWH.ByteProtocol
{
    public class ByteBufferParseProperty : ParseProperty<CircularByteBuffer>
    {
        public ByteBufferParseProperty(AbstractProperty property) : base(property)
        {
        }

        public override bool tryGetData(CircularByteBuffer dataQueue)
        {
            bool isGetData = false;
            int offset = getOffset();
            int length = getLength();
            if (dataQueue.ReadableBytes >= offset + length)
            {
                //如果数据足够长，则获取数据
                //byte[] data = new byte[length];
                //byteBuf.getBytes(byteBuf.readerIndex() + offset, data);

                byte[] data= dataQueue.GetBytes(offset, length);

                setData(data, 0, length);
                isGetData = true;
            }
            return isGetData;
        }
    }
}
